package zx.x.modules.yshbms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import zx.x.common.utils.PageUtils;
import zx.x.common.utils.Query;
import zx.x.modules.yshbms.dao.GoodsDao;
import zx.x.modules.yshapp.entity.GoodsEntity;
import zx.x.modules.yshbms.service.GoodsService;

import java.util.Map;


@Service("goodsService")
public class GoodsServiceImpl extends ServiceImpl<GoodsDao, GoodsEntity> implements GoodsService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String)params.get("name");
        String communityId = (String)params.get("communityId");
        String type = (String)params.get("type");
        String onSale = (String)params.get("onSale");
        QueryWrapper<GoodsEntity> goodsEntityQueryWrapper =new QueryWrapper<GoodsEntity>();
        if(StringUtils.isNotBlank(name)){
            goodsEntityQueryWrapper.like("name",name);
        }
        if(StringUtils.isNotBlank(communityId)){
            goodsEntityQueryWrapper.eq("community_id",communityId);
        }
        if(StringUtils.isNotBlank(type)){
            goodsEntityQueryWrapper.eq("type",type);
        }
        if(StringUtils.isNotBlank(onSale)){
            goodsEntityQueryWrapper.eq("on_sale",onSale);
        }
        goodsEntityQueryWrapper.eq("delete_flag",0);
        goodsEntityQueryWrapper.orderBy(true,false,"update_time");
        IPage<GoodsEntity> page = this.page(
                new Query<GoodsEntity>().getPage(params),
                goodsEntityQueryWrapper
        );

        return new PageUtils(page);
    }
}